package icasue.net.socket.driver.event;

import com.alibaba.fastjson.JSON;
import icasue.net.base.annotations.NotNull;
import icasue.net.base.annotations.Nullable;
import icasue.net.protocol.carfun.common.CommandResponse;
import icasue.net.socket.driver.CommandDriver;
import icasue.net.socket.exception.ClientConnectException;
import icasue.net.socket.exception.CommandExecException;
import icasue.net.socket.exception.ProtocolUnSupportException;
import icasue.net.socket.model.register.RegisterInfo;
import icasue.net.socket.thread.SocketProxy;
import icasue.net.protocol.carfun.commands.EventCommand;

/**
 * @Author: Qiao Hang
 * @CreateDate: 2021/3/23 上午10:04
 * @UpdateDate:
 * @Description:
 */
public interface EventCommandDriver<C extends EventCommand,RInfo extends RegisterInfo> extends CommandDriver<C> {

    /**
     * Core method for deal BizEventCommand's processor.
     * BizCommandDriver中唯一抽象的方法，dealBizEvent, 用于服务端处理不同的类型的bizCommand请求，
     * 返回统一的CommandResponse<JSON> 抽象格式, 可能抛出 {@CommandExecException} 被服务端socket捕获，写回客户端.
     * BizCommand会生成相应的BizEvent载入消息池，由channel线程进行注册客户端的消息分发.
     * @param command
     * @param proxy
     * @param registerInfo
     * @param channelId
     * @param data
     * @return
     * @throws ProtocolUnSupportException
     * @throws CommandExecException
     * @throws ClientConnectException
     */
    @Nullable
    CommandResponse<JSON> dealEventCommand(@NotNull C command,
                                           @NotNull SocketProxy<RInfo> proxy,
                                           @NotNull RInfo registerInfo,
                                           @NotNull Object channelId,
                                           @Nullable JSON data)throws ProtocolUnSupportException, CommandExecException, ClientConnectException;

}
